package com.ayoka.mvp;

import com.ayoka.R;
import com.ayoka.base.BasePresenter;
import com.ayoka.base.IBaseView;
import com.ayoka.bean.BaseResponse;
import com.ayoka.http.API;
import com.ayoka.http.OkHttpListener;
import com.jcp.baselibrary.utils.UIUtils;

/**
 * Created by gabriel on 2017/3/5.
 */

public interface VerifyMobileMVP {

    interface VerifyMobileModel {

    }

    interface IVerifyMobileView extends IBaseView {

        void onSendVerifyCodeCallback(boolean isSuccess);

        void onVerifyMobileCallback(boolean isSuccess);
    }

    class VerifyMobilePresenter extends BasePresenter<IVerifyMobileView> {

        public void sendVerifyCode(String mobile) {
            mViewRef.get().showWaitDialog(UIUtils.getString(R.string.loading));
            API.sendVerifyCode(this, mobile, new OkHttpListener<BaseResponse>() {
                @Override
                public void onSuccess(BaseResponse response) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().onSendVerifyCodeCallback(true);
                }

                @Override
                public void onFailure(int errorCode, String errorMessage) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().showToast(errorMessage);
                    mViewRef.get().onSendVerifyCodeCallback(false);
                }
            });
        }

        public void verifyMobile(String mobile, String verifyCode) {
            mViewRef.get().showWaitDialog(UIUtils.getString(R.string.loading));
            API.verifyCode(this, mobile, verifyCode, new OkHttpListener<BaseResponse>() {
                @Override
                public void onSuccess(BaseResponse response) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().onVerifyMobileCallback(true);
                }

                @Override
                public void onFailure(int errorCode, String errorMessage) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().showToast(errorMessage);
                    mViewRef.get().onVerifyMobileCallback(false);
                }
            });
        }
    }
}
